package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商品品牌接口")
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {
    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //    /admin/product/baseTrademark/{page}/{size}
    @ApiOperation(value = "分页列表")
    @GetMapping("{page}/{size}")
    public Result getTrademarkPage(@PathVariable Long page,
                                   @PathVariable Long size) {
        Page<BaseTrademark> pageParam = new Page<>(page, size);
        IPage<BaseTrademark> pageModel = baseTrademarkService.getPage(pageParam);

        return Result.ok(pageModel);
    }

    //    admin/product/baseTrademark/get/{id}
    @ApiOperation(value = "获取BaseTrademark")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable String id) {
        BaseTrademark byId = baseTrademarkService.getById(id);
        return Result.ok(byId);
    }

    @ApiOperation(value = "新增BaseTrademark")
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {//传参实体类
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
    @ApiOperation(value = "修改BaseTrademark")
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
    @ApiOperation(value = "删除BaseTrademark")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }
}
